package server.qiang.Process;


import java.net.Socket;

import server.qiang.Thread.Server;
import server.qiang.database.IpMap;
import server.qiang.database.IpObject;
import common.harvin.potocol.Request;
import common.harvin.potocol.Response;

public class UpdateIp {
private Socket socket;
private IpMap ipmap;	
private IpObject ipobject;	
private Request request;	
	
public Response updateip(Socket socket,Request request,IpMap ipmap)
{
	this.socket=socket;
	this.request=request;
	this.ipmap=ipmap;
	
	//System.out.println("command:"+request.getCommand());
	System.out.println("sender:"+request.getSender());
	
	System.out.println("send_Date:"+request.getSend_Date());
	
	
	
	
	Response response=new Response();
	response.setFor_command(request.getCommand());
	response.setSend_Date(request.getSend_Date());
	
	
	ipobject =new IpObject();
	//ipobject.setIp(Server.ip);
	//ipobject.setPort(Server.port);
	ipobject.setIp(socket.getInetAddress().toString());
	
	ipobject.setPort(socket.getPort());
	
	System.out.println("ip:"+ipobject.getIp());
	System.out.println("port:"+ipobject.getPort());
	
	ipmap.add(request.getSender(), ipobject);
	
	response.setResult(true);
	response.addData("port:", String.valueOf(ipobject.getPort()));
	
	return response;
}

}
